// https://leetcode-cn.com/problems/find-the-duplicate-number/
// 解决数组问题的思路 当看到 元素的取值范围在数组长度范围内时 就想到 下标与元素之间相互转换的关系
class Solution {
public:
    int findDuplicate(vector<int>& nums) {
        int slow = 0, fast = 0;
        do {
            slow = nums[slow];
            fast = nums[nums[fast]];
        } while (slow != fast);
        slow = 0;
        while (slow != fast) {
            slow = nums[slow];
            fast = nums[fast];
        }
        return slow;
    }
};